// pages/my/my.js
Page({
  /**
   * 页面的初始数据
   */
  data: {
    show: false,
    userId: '',
    questionList: '',
    userInfo: [],
    fanList: [],
    followedList: [],
    travelogueList: [],
    strategyList: [], //获取当前景点对应的攻略
  },
  showPopup() {
    this.setData({
      show: true
    });
  },

  onClose() {
    this.setData({
      show: false
    });
  },
  //前往我的订单
  goMyOrder() {
    wx.navigateTo({
      url: '/pages/my/myOrder/myOrder',
    })
  },
  //前往全部攻略
  goAllStrategy() {
    wx.navigateTo({
      url: '/pages/index/userCenter/allStrategy/allStrategy',
    })
  },

  // 攻略详情     
  getStrategy() {
    wx.request({
      url: `http://localhost:8080/strategy/strategy/list`,
      method: 'GET',
      header: {
        Authorization: getApp().globalData.authorization
      },
      data: {
        userId: this.data.userId
      },
      success: (resp) => {
        this.setData({
          strategyList: resp.data.rows
        });
      },
      complete: (resp) => {
      }
    })
  },

  //前往全部手记
  goAllTravelogue() {
    wx.navigateTo({
      url: '/pages/index/userCenter/allTravelogue/allTravelogue',
    })
  },
  //前往修改用户信息
  goEditUserInformation() {
    wx.navigateTo({
      url: '/pages/my/editMyInformation/editMyInformation?userId='+this.data.userId,
    })
  },
  //封装获取我的信息函数
  getUserInfo() {
    wx.request({
      url: `http://localhost:8080/system/user/${this.data.userId}`,
      method: 'GET',
      header: {
        Authorization: getApp().globalData.authorization
      },
      success: (resp) => {
        this.setData({
          userInfo: resp.data.data
        })
      }
    })
  },

  //获取当前用户的粉丝
  getFans() {
    wx.request({
      url: `http://localhost:8080/user/followed/fans/${this.data.userId}`,
      method: 'GET',
      header: {
        Authorization: getApp().globalData.authorization
      },
      success: (resp) => {
        this.setData({
          fanList: resp.data.rows
        })
      }
    })
  },

  //获取当前用户关注的用户
  getFollowed() {
    wx.request({
      url: `http://localhost:8080/user/followed/followed/${this.data.userId}`,
      method: 'GET',
      header: {
        Authorization: getApp().globalData.authorization
      },
      success: (resp) => {
        this.setData({
          followedList: resp.data.rows
        })
      }
    })
  },


  //封装获取该个用户下的所有回答
  getQuestionByUserId() {
    wx.request({
      url: `http://localhost:8080/content/question/user/${this.data.userId}`,
      method: 'GET',
      header: {
        Authorization: getApp().globalData.authorization
      },
      success: (resp) => {
        this.setData({
          questionList: resp.data.rows
        })
      }
    })
  },




  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    var loginfo= getApp().globalData.loginfo;
    this.setData({
      userId: loginfo.userId
    })
    this.getUserInfo()
    this.getQuestionByUserId()
    this.getFans()
    this.getFollowed()
    this.getStrategy()
    wx.request({
      url: 'http://localhost:8080/travelogue/travelogue/list',
      method: 'GET',
      header: {
        Authorization: getApp().globalData.authorization
      },
      success: (resp) => {
        this.setData({
          travelogueList: resp.data.rows
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.getQuestionByUserId()
    this.getFans()
    this.getFollowed()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})